<%= email_description(@maily_email) %>

<ul class="action_bar">
  <li>
    <%= link_to 'Edit', edit_maily_email_path(maily_params) %>
  </li>

  <li class="languages">
    <% if Maily.available_locales.present? %>
      <ul>
        <li>
          <%= icon 'globe' %> Languages
        </li>
        <% Maily.available_locales.each do |locale| %>
          <li><%= link_to locale.upcase, url_for(params.to_unsafe_h.merge(locale: locale)) %></li>
        <% end %>
      </ul>
    <% end %>
  </li>

  <% if Maily.allowed_action?(:deliver) %>
    <li class="splitter">|</li>

    <li>
      <%= form_tag(deliver_maily_email_path(maily_params), method: :post, class: 'mail_deliver') do %>
        <ul>
          <li>Send to</li>
          <li><%= email_field_tag :to, nil, placeholder: "Enter email", required: true %></li>
          <li><%= submit_tag 'Send', class: 'button' %></li>
        </ul>
      <% end %>
    </li>
  <% end %>
</ul>

<% if @maily_email.has_versions? %>
  <fieldset class="version_list_wrapper">
    <legend>Versions</legend>
    <ul class="version_list">
      <% @maily_email.versions.each do |_version_key, version_email| %>
        <li><%= link_to version_email.version.humanize, maily_email_path(maily_params.merge(version: version_email.version)), class: version_list_class(version_email) %></li>
      <% end %>
    </ul>
  </fieldset>
<% end %>

<div class="mail_preview">
  <ul class="mail_details">
    <% if @email.subject %><li><b>Subject</b> <%= @email.subject %></li><% end %>
    <% if @email.from %><li><b>From</b> <%= @email.from.join(', ') %></li><% end %>
    <% if @email.to %><li><b>To</b> <%= @email.to.join(', ') %></li><% end %>
    <% if @email.cc %><li><b>Cc</b> <%= @email.cc.join(', ') %></li><% end %>
    <% if @email.bcc %><li><b>Bcc</b> <%= @email.bcc.join(', ') %></li><% end %>
    <% if @email.reply_to %><li><b>Reply to</b> <%= @email.reply_to.join(', ') %></li><% end %>
  </ul>

  <% if @email.html_part && @email.text_part %>
    <ul class="format_mail">
      <li><%= link_to 'HTML', url_for(params.to_unsafe_h.merge(part: 'html')), class: part_class('html') %></li>
      <li><%= link_to 'TEXT', url_for(params.to_unsafe_h.merge(part: 'text')), class: part_class('text') %></li>
    </ul>
  <% end %>

  <% if @email.html_part || @email.text_part || @email.body.present? %>
    <iframe class="mail_iframe" onload='resizeIframe(this)' src="<%= raw_maily_email_path(maily_params) %>" frameborder="1" width="100%"></iframe>
  <% end %>

  <% if @email.has_attachments? %>
    <ul class="mail_attachments">
      <li>Attachments:</li>
      <li>
        <ul>
          <% @email.attachments.each do |attachment| %>
            <li>
              <%= icon 'paperclip' %>
              <%= link_to attachment.filename, attachment_maily_email_path(maily_params.merge(attachment: attachment.filename)) %>
            </li>
          <% end %>
        </ul>
      </li>
    </ul>
  <% end %>
</div>
